#include "ParentNode.h"

	namespace scenegraph{

	ParentNode::ParentNode() 
	  : shape(0) 
	{
	}

	ParentNode::~ParentNode() 
	{
		if ( shape != 0 ) 
		{
			delete shape;
		}
	}

	void ParentNode::addChild( SceneGraphNode* childNode ) 
	{
		children.push_back(childNode);
	}

	void ParentNode::setShape( ShapeNode* shapeNode )
	{
		shape = shapeNode; 
	}

	void ParentNode::draw() {
		glPushMatrix();
		glMultMatrixf( transform );
		// first draw children
		int size = children.size();

		for(int i = 0; i < children.size(); i++)
		{
	  			children[i]->draw();
		}
		// draw itself
		if ( shape!=0 ) shape->draw();
		glPopMatrix();
	}

	void ParentNode::destroy() {
		// first delete children
		for(unsigned int i = 0; i < children.size(); i++)
		{
			children[i]->destroy();
			delete children[i];
		}
	}
}